package stsj.meddroid.screen;

import stsj.meddroid.MainAppListener;
import stsj.meddroid.Resources;
import stsj.meddroid.Settings;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.audio.Sound;
import com.badlogic.gdx.graphics.Camera;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.scenes.scene2d.Stage;
import com.badlogic.gdx.scenes.scene2d.actors.Button;
import com.badlogic.gdx.scenes.scene2d.actors.Button.ClickListener;

public class ViroScreen implements Screen, InputProcessor {

	private SpriteBatch batch;
	private Camera camera;

	private Stage stage;

	private Button locked[];

	private Button back;
	private Button forward;
	private Button close;

	private Button slimeGreenButton;
	private Button slimeBlueButton;
	private Button slimeOrangeButton;
	private Button slimeRedButton;

	private Button duriGreenButton;
	private Button duriVioletButton;
	private Button duriOrangeButton;

	private Button gebukGreenButton;
	private Button gebukPinkButton;
	private Button gebukRedButton;

	private Button petelurVioletButton;
	private Button petelurYellowButton;
	private Button petelurBlueButton;

	private Button rbj;
	private Button spt;
	private Button htn;
	private Button smc;

	private MainAppListener mainListener;

	int x;
	int y;

	private static final int VP_WIDTH = 480;
	private static final int VP_HEIGHT = 320;

	private static int currentShown;

	private static final int SLIME = 0;
	private static final int DURI = 1;
	private static final int GEBUK = 2;
	private static final int PETELUR = 3;
	private static final int BLACK = 4;

	public static final int SLIME_GREEN = 0;
	public static final int SLIME_BLUE = 1;
	public static final int SLIME_RED = 2;
	public static final int SLIME_ORANGE = 3;

	public static final int DURI_GREEN = 0;
	public static final int DURI_ORANGE = 1;
	public static final int DURI_VIOLET = 2;

	public static final int GEBUK_GREEN = 0;
	public static final int GEBUK_PINK = 1;
	public static final int GEBUK_RED = 2;

	public static final int PETELUR_BLUE = 0;
	public static final int PETELUR_VIOLET = 1;
	public static final int PETELUR_YELLOW = 2;

	public static final int RBJ = 0;
	public static final int SPT = 1;
	public static final int HTN = 2;
	public static final int SMC = 3;

	public TextureRegion viroClose[];
	public TextureRegion viroLocked[];

	public TextureRegion viroUnknown;
	public TextureRegion viroBookBg;
	public TextureRegion viroBack[];
	public TextureRegion viroForward[];
	public TextureRegion slimeBlue[];
	public TextureRegion slimeRed[];
	public TextureRegion slimeGreen[];
	public TextureRegion slimeOrange[];

	public TextureRegion duriOrange[];
	public TextureRegion duriGreen[];
	public TextureRegion duriViolet[];

	public TextureRegion gebukPink[];
	public TextureRegion gebukGreen[];
	public TextureRegion gebukRed[];

	public TextureRegion petelurBlue[];
	public TextureRegion petelurViolet[];
	public TextureRegion petelurYellow[];

	public TextureRegion blackRBJ[];
	public TextureRegion blackSPT[];
	public TextureRegion blackHTN[];
	public TextureRegion blackSMC[];

	public TextureRegion viroSlimeBlue;
	public TextureRegion viroSlimeGreen;
	public TextureRegion viroSlimeRed;
	public TextureRegion viroSlimeOrange;

	public TextureRegion viroDuriGreen;
	public TextureRegion viroDuriOrange;
	public TextureRegion viroDuriViolet;

	public TextureRegion viroGebukGreen;
	public TextureRegion viroGebukPink;
	public TextureRegion viroGebukRed;

	public TextureRegion viroPetelurBlue;
	public TextureRegion viroPetelurViolet;
	public TextureRegion viroPetelurYellow;

	public TextureRegion viroBlackRBJ;
	public TextureRegion viroBlackSPT;
	public TextureRegion viroBlackHTN;
	public TextureRegion viroBlackSMC;

	public TextureRegion viroTextSlime[];
	public TextureRegion viroTextDuri[];
	public TextureRegion viroTextGebuk[];
	public TextureRegion viroTextPetelur[];
	public TextureRegion viroTextBlack[];

	private int selection = 1;
	private Sound clickSound;
	private static final int x3 = 350 - 80;

	private final static int defaultY = 10;

	public ViroScreen(MainAppListener mainListener) {
		// TODO Auto-generated constructor stub
		this.mainListener = mainListener;
		camera = Resources.camera;
		stage = new Stage(480, 320, true);

		clickSound = Resources.clickSound;

		viroBack = new TextureRegion[2];
		viroBack[0] = new TextureRegion(Resources.buttonDll, 64 * 6, 0, 64, 64);
		viroBack[1] = new TextureRegion(Resources.buttonDll, 64 * 7, 0, 64, 64);

		viroForward = new TextureRegion[2];
		viroForward[0] = new TextureRegion(Resources.buttonDll, 64 * 6, 0, 64,
				64);
		viroForward[1] = new TextureRegion(Resources.buttonDll, 64 * 7, 0, 64,
				64);
		viroForward[0].flip(true, false);
		viroForward[1].flip(true, false);

		viroClose = new TextureRegion[2];
		viroClose[0] = new TextureRegion(Resources.buttonDll, 64 * 6, 64, 32,
				32);
		viroClose[1] = new TextureRegion(Resources.buttonDll, 64 * 6 + 32, 64,
				32, 32);

		viroLocked = new TextureRegion[2];
		viroLocked[0] = new TextureRegion(Resources.buttonDll, 64 * 4, 64 * 7,
				64, 64);
		viroLocked[1] = new TextureRegion(Resources.buttonDll, 64 * 5, 64 * 7,
				64, 64);

		viroBookBg = new TextureRegion(Resources.organmenulayout, 512, 1024,
				480, 320);

		slimeBlue = new TextureRegion[2];
		slimeRed = new TextureRegion[2];
		slimeGreen = new TextureRegion[2];
		slimeOrange = new TextureRegion[2];

		duriOrange = new TextureRegion[2];
		duriGreen = new TextureRegion[2];
		duriViolet = new TextureRegion[2];

		gebukPink = new TextureRegion[2];
		gebukGreen = new TextureRegion[2];
		gebukRed = new TextureRegion[2];

		petelurBlue = new TextureRegion[2];
		petelurViolet = new TextureRegion[2];
		petelurYellow = new TextureRegion[2];

		blackRBJ = new TextureRegion[2];
		blackSPT = new TextureRegion[2];
		blackHTN = new TextureRegion[2];
		blackSMC = new TextureRegion[2];

		slimeGreen[0] = new TextureRegion(Resources.buttonDll, 0, 64 * 3, 64,
				64);
		slimeGreen[1] = new TextureRegion(Resources.buttonDll, 64, 64 * 3, 64,
				64);
		slimeBlue[0] = new TextureRegion(Resources.buttonDll, 64, 64, 64, 64);
		slimeBlue[1] = new TextureRegion(Resources.buttonDll, 0, 64, 64, 64);
		slimeRed[0] = new TextureRegion(Resources.buttonDll, 0, 0, 64, 64);
		slimeRed[1] = new TextureRegion(Resources.buttonDll, 64, 0, 64, 64);
		slimeOrange[0] = new TextureRegion(Resources.buttonDll, 0, 64 * 2, 64,
				64);
		slimeOrange[1] = new TextureRegion(Resources.buttonDll, 64, 64 * 2, 64,
				64);

		duriOrange[0] = new TextureRegion(Resources.buttonDll, 0, 64 * 4, 64,
				64);
		duriOrange[1] = new TextureRegion(Resources.buttonDll, 64, 64 * 4, 64,
				64);
		duriGreen[0] = new TextureRegion(Resources.buttonDll, 0, 64 * 6, 64, 64);
		duriGreen[1] = new TextureRegion(Resources.buttonDll, 64, 64 * 6, 64,
				64);
		duriViolet[0] = new TextureRegion(Resources.buttonDll, 0, 64 * 5, 64,
				64);
		duriViolet[1] = new TextureRegion(Resources.buttonDll, 64, 64 * 5, 64,
				64);

		gebukPink[0] = new TextureRegion(Resources.buttonDll, 0, 64 * 7, 64, 64);
		gebukPink[1] = new TextureRegion(Resources.buttonDll, 64, 64 * 7, 64,
				64);
		gebukGreen[0] = new TextureRegion(Resources.buttonDll, 128, 64, 64, 64);
		gebukGreen[1] = new TextureRegion(Resources.buttonDll, 64 * 3, 64, 64,
				64);
		gebukRed[0] = new TextureRegion(Resources.buttonDll, 128, 0, 64, 64);
		gebukRed[1] = new TextureRegion(Resources.buttonDll, 128 + 64, 0, 64,
				64);

		petelurBlue[0] = new TextureRegion(Resources.buttonDll, 128, 64 * 4,
				64, 64);
		petelurBlue[1] = new TextureRegion(Resources.buttonDll, 64 * 3, 64 * 4,
				64, 64);
		petelurViolet[0] = new TextureRegion(Resources.buttonDll, 128, 128, 64,
				64);
		petelurViolet[1] = new TextureRegion(Resources.buttonDll, 64 * 3,
				64 * 2, 64, 64);
		petelurYellow[0] = new TextureRegion(Resources.buttonDll, 128, 64 * 3,
				64, 64);
		petelurYellow[1] = new TextureRegion(Resources.buttonDll, 64 * 3,
				64 * 3, 64, 64);

		blackRBJ[0] = new TextureRegion(Resources.buttonDll, 128, 64 * 5, 64,
				64);
		blackRBJ[1] = new TextureRegion(Resources.buttonDll, 64 * 3, 64 * 5,
				64, 64);
		blackSPT[0] = new TextureRegion(Resources.buttonDll, 128, 64 * 6, 64,
				64);
		blackSPT[1] = new TextureRegion(Resources.buttonDll, 64 * 3, 64 * 6,
				64, 64);
		blackHTN[0] = new TextureRegion(Resources.buttonDll, 128, 64 * 7, 64,
				64);
		blackHTN[1] = new TextureRegion(Resources.buttonDll, 64 * 3, 64 * 7,
				64, 64);
		blackSMC[0] = new TextureRegion(Resources.buttonDll, 64 * 4, 0, 64, 64);
		blackSMC[1] = new TextureRegion(Resources.buttonDll, 64 * 5, 0, 64, 64);

		viroSlimeBlue = new TextureRegion(Resources.kuman, 0, 0, 128, 128);
		viroSlimeGreen = new TextureRegion(Resources.kuman, 128 * 2, 0, 128,
				128);
		viroSlimeRed = new TextureRegion(Resources.kuman, 128, 0, 128, 128);
		viroSlimeOrange = new TextureRegion(Resources.kuman, 128 * 3, 0, 128,
				128);

		viroDuriGreen = new TextureRegion(Resources.kuman, 0, 128 * 2, 128, 128);
		viroDuriOrange = new TextureRegion(Resources.kuman, 128, 128 * 2, 128,
				128);
		viroDuriViolet = new TextureRegion(Resources.kuman, 128 * 2, 128 * 2,
				128, 128);

		viroGebukGreen = new TextureRegion(Resources.kuman, 128 * 3, 128 * 2,
				128, 128);
		viroGebukPink = new TextureRegion(Resources.kuman, 0, 128 * 3, 128, 128);
		viroGebukRed = new TextureRegion(Resources.kuman, 128 * 1, 128 * 3,
				128, 128);

		viroPetelurBlue = new TextureRegion(Resources.kuman, 128 * 2, 128 * 3,
				128, 128);
		viroPetelurViolet = new TextureRegion(Resources.kuman, 128 * 3,
				128 * 3, 128, 128);
		viroPetelurYellow = new TextureRegion(Resources.kuman, 0, 128 * 4, 128,
				128);

		viroBlackRBJ = new TextureRegion(Resources.kuman, 0, 128, 128, 128);
		viroBlackSPT = new TextureRegion(Resources.kuman, 128, 128, 128, 128);
		viroBlackHTN = new TextureRegion(Resources.kuman, 128 * 2, 128, 128,
				128);
		viroBlackSMC = new TextureRegion(Resources.kuman, 128 * 3, 128, 128,
				128);

		viroTextSlime = new TextureRegion[5];
		viroTextSlime[SLIME_GREEN] = new TextureRegion(Resources.viroText, 0,
				0, 160, 160);
		viroTextSlime[SLIME_ORANGE] = new TextureRegion(Resources.viroText,
				161, 0, 160, 160);
		viroTextSlime[SLIME_RED] = new TextureRegion(Resources.viroText, 322,
				0, 160, 160);
		viroTextSlime[SLIME_BLUE] = new TextureRegion(Resources.viroText, 483,
				0, 160, 160);
		viroTextDuri = new TextureRegion[5];
		viroTextDuri[DURI_GREEN] = new TextureRegion(Resources.viroText, 644,
				0, 160, 160);
		viroTextDuri[DURI_VIOLET] = new TextureRegion(Resources.viroText, 0,
				160, 160, 160);
		viroTextDuri[DURI_ORANGE] = new TextureRegion(Resources.viroText, 161,
				160, 160, 160);

		viroTextGebuk = new TextureRegion[5];
		viroTextGebuk[GEBUK_GREEN] = new TextureRegion(Resources.viroText, 322,
				160, 160, 160);
		viroTextGebuk[GEBUK_RED] = new TextureRegion(Resources.viroText, 483,
				160, 160, 160);
		viroTextGebuk[GEBUK_PINK] = new TextureRegion(Resources.viroText, 645,
				160, 160, 160);
		viroTextPetelur = new TextureRegion[5];
		viroTextPetelur[PETELUR_BLUE] = new TextureRegion(Resources.viroText,
				0, 320, 160, 160);
		viroTextPetelur[PETELUR_VIOLET] = new TextureRegion(Resources.viroText,
				322, 320, 160, 160);
		viroTextPetelur[PETELUR_YELLOW] = new TextureRegion(Resources.viroText,
				161, 320, 160, 160);

		viroTextBlack = new TextureRegion[5];
		viroTextBlack[RBJ] = new TextureRegion(Resources.viroText, 483, 320,
				160, 160);
		viroTextBlack[SPT] = new TextureRegion(Resources.viroText, 645, 320,
				160, 160);
		viroTextBlack[HTN] = new TextureRegion(Resources.viroText, 0, 480, 160,
				160);
		viroTextBlack[SMC] = new TextureRegion(Resources.viroText, 161, 480,
				160, 160);

		locked = new Button[18];
		for (int i = 0; i < 18; i++) {
			locked[i] = new Button("Locked " + i, viroLocked[0], viroLocked[1]);
			locked[i].y = defaultY;
			locked[i].clickListener = new ClickListener() {

				@Override
				public void clicked(Button arg0) {
					// TODO Auto-generated method stub
					Resources.playSound(Resources.lockedSound);
				}

			};
		}

		back = new Button("Back", viroBack[0], viroBack[1]);
		forward = new Button("Forward", viroForward[0], viroForward[1]);

		slimeGreenButton = new Button("Slime green", slimeGreen[0],
				slimeGreen[1]);
		slimeBlueButton = new Button("Slime blue", slimeBlue[0], slimeBlue[1]);
		slimeOrangeButton = new Button("Slime orange", slimeOrange[0],
				slimeOrange[1]);
		slimeRedButton = new Button("Slime red", slimeRed[0], slimeRed[1]);

		duriGreenButton = new Button("Duri green", duriGreen[0], duriGreen[1]);
		duriVioletButton = new Button("Duri violet", duriViolet[0],
				duriViolet[1]);
		duriOrangeButton = new Button("Duri orange", duriOrange[0],
				duriOrange[1]);

		gebukGreenButton = new Button("Gebuk green", gebukGreen[0],
				gebukGreen[1]);
		gebukPinkButton = new Button("Gebuk pink", gebukPink[0], gebukPink[1]);
		gebukRedButton = new Button("Gebuk red", gebukRed[0], gebukRed[1]);

		petelurVioletButton = new Button("Petelur violet", petelurViolet[0],
				petelurViolet[1]);
		petelurYellowButton = new Button("Petelur yellow", petelurYellow[0],
				petelurYellow[1]);
		petelurBlueButton = new Button("Petelur blue", petelurBlue[0],
				petelurBlue[1]);

		rbj = new Button("rbj", blackRBJ[0], blackRBJ[1]);
		spt = new Button("spt", blackSPT[0], blackSPT[1]);
		htn = new Button("htn", blackHTN[0], blackHTN[1]);
		smc = new Button("smc", blackSMC[0], blackSMC[1]);

		close = new Button("Close viro", viroClose[0], viroClose[1]);
		close.x = 480 - close.width - 30;
		close.y = 320 - close.height - 10;

		close.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				backToMainMenu();
			}

		};

		currentShown = SLIME;
		if (Settings.unlockedViro[SLIME][SLIME_GREEN]) {
			selection = SLIME_GREEN;
		} else if (Settings.unlockedViro[SLIME][SLIME_BLUE]) {
			selection = SLIME_BLUE;
		} else if (Settings.unlockedViro[SLIME][SLIME_ORANGE]) {
			selection = SLIME_ORANGE;
		} else if (Settings.unlockedViro[SLIME][SLIME_RED]) {
			selection = SLIME_RED;
		} else {
			selection = 99;
		}

		batch = Resources.batch;
		x = VP_WIDTH / 2;
		y = VP_HEIGHT / 2;
		camera.position.set(x, y, 0);

		// setting scene...
		back.x = 0;
		back.y = 0;

		forward.x = 480 - forward.width;
		forward.y = 0;

		slimeGreenButton.x = 120;
		slimeGreenButton.y = 10;
		locked[0].x = slimeGreenButton.x;

		slimeBlueButton.x = slimeGreenButton.x + slimeBlueButton.width;
		slimeBlueButton.y = 10;
		locked[1].x = slimeBlueButton.x;

		slimeRedButton.x = slimeBlueButton.x + slimeRedButton.width;
		slimeRedButton.y = 10;
		locked[2].x = slimeRedButton.x;

		slimeOrangeButton.x = slimeRedButton.x + slimeOrangeButton.width;
		slimeOrangeButton.y = 10;
		locked[3].x = slimeOrangeButton.x;

		duriGreenButton.x = 150;
		duriGreenButton.y = 10;
		locked[4].x = duriGreenButton.x;

		duriOrangeButton.x = duriGreenButton.x + duriGreenButton.width;
		duriOrangeButton.y = 10;
		locked[5].x = duriOrangeButton.x;
		duriVioletButton.x = duriOrangeButton.x + duriVioletButton.width;
		duriVioletButton.y = 10;
		locked[6].x = duriVioletButton.x;

		gebukGreenButton.x = 150;
		gebukGreenButton.y = 10;
		locked[7].x = gebukGreenButton.x;

		gebukPinkButton.x = gebukGreenButton.x + gebukPinkButton.width;
		gebukPinkButton.y = 10;
		locked[8].x = gebukPinkButton.x;

		gebukRedButton.x = gebukPinkButton.x + gebukRedButton.width;
		gebukRedButton.y = 10;
		locked[9].x = gebukRedButton.x;

		petelurBlueButton.x = 150;
		petelurBlueButton.y = 10;
		locked[10].x = petelurBlueButton.x;
		petelurVioletButton.x = petelurBlueButton.x + petelurVioletButton.width;
		petelurVioletButton.y = 10;
		locked[11].x = petelurVioletButton.x;
		petelurYellowButton.x = petelurVioletButton.x
				+ petelurYellowButton.width;
		petelurYellowButton.y = 10;
		locked[12].x = petelurYellowButton.x;

		rbj.x = 120;
		rbj.y = 10;
		locked[13].x = rbj.x;

		spt.x = rbj.x + spt.width;
		spt.y = 10;
		locked[14].x = spt.x;

		htn.x = spt.x + htn.width;
		htn.y = 10;
		locked[15].x = htn.x;

		smc.x = htn.x + smc.width;
		smc.y = 10;
		locked[16].x = smc.x;

		back.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				playSound(clickSound);
				switch (currentShown) {
				case SLIME: {

					break;
				}
				case DURI: {
					currentShown--;
					if (Settings.unlockedViro[SLIME][SLIME_GREEN]) {
						selection = SLIME_GREEN;
					} else if (Settings.unlockedViro[SLIME][SLIME_BLUE]) {
						selection = SLIME_BLUE;
					} else if (Settings.unlockedViro[SLIME][SLIME_RED]) {
						selection = SLIME_RED;
					} else if (Settings.unlockedViro[SLIME][SLIME_ORANGE]) {
						selection = SLIME_ORANGE;
					} else {
						selection = 99;
					}
					break;
				}
				case GEBUK: {
					currentShown--;
					if (Settings.unlockedViro[DURI][DURI_GREEN]) {
						selection = DURI_GREEN;
					} else if (Settings.unlockedViro[DURI][DURI_ORANGE]) {
						selection = DURI_ORANGE;
					} else if (Settings.unlockedViro[DURI][DURI_VIOLET]) {
						selection = DURI_VIOLET;
					} else {
						selection = 99;
					}
					break;
				}
				case PETELUR: {
					currentShown--;
					if (Settings.unlockedViro[GEBUK][GEBUK_GREEN]) {
						selection = GEBUK_GREEN;
					} else if (Settings.unlockedViro[GEBUK][GEBUK_PINK]) {
						selection = GEBUK_PINK;
					} else if (Settings.unlockedViro[GEBUK][GEBUK_RED]) {
						selection = GEBUK_RED;
					} else {
						selection = 99;
					}
					break;
				}
				case BLACK: {
					currentShown--;
					if (Settings.unlockedViro[PETELUR][PETELUR_BLUE]) {
						selection = PETELUR_BLUE;
					} else if (Settings.unlockedViro[PETELUR][PETELUR_VIOLET]) {
						selection = PETELUR_VIOLET;
					} else if (Settings.unlockedViro[PETELUR][PETELUR_YELLOW]) {
						selection = PETELUR_YELLOW;
					} else {
						selection = 99;
					}
					break;
				}

				default:
					break;
				}
				postRender();
			}

		};

		forward.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				playSound(clickSound);
				switch (currentShown) {
				case SLIME: {
					currentShown++;
					if (Settings.unlockedViro[DURI][DURI_GREEN]) {
						selection = DURI_GREEN;
					} else if (Settings.unlockedViro[DURI][DURI_ORANGE]) {
						selection = DURI_ORANGE;
					} else if (Settings.unlockedViro[DURI][DURI_VIOLET]) {
						selection = DURI_VIOLET;
					} else {
						selection = 99;
					}
					break;
				}
				case DURI: {
					currentShown++;
					if (Settings.unlockedViro[GEBUK][GEBUK_GREEN]) {
						selection = GEBUK_GREEN;
					} else if (Settings.unlockedViro[GEBUK][GEBUK_PINK]) {
						selection = GEBUK_PINK;
					} else if (Settings.unlockedViro[GEBUK][GEBUK_RED]) {
						selection = GEBUK_RED;
					} else {
						selection = 99;
					}
					break;
				}
				case GEBUK: {
					currentShown++;
					if (Settings.unlockedViro[PETELUR][PETELUR_BLUE]) {
						selection = PETELUR_BLUE;
					} else if (Settings.unlockedViro[PETELUR][PETELUR_VIOLET]) {
						selection = PETELUR_VIOLET;
					} else if (Settings.unlockedViro[PETELUR][PETELUR_YELLOW]) {
						selection = PETELUR_YELLOW;
					} else {
						selection = 99;
					}
					break;
				}
				case PETELUR: {
					currentShown++;
					if (Settings.unlockedViro[BLACK][RBJ]) {
						selection = RBJ;
					} else if (Settings.unlockedViro[BLACK][SPT]) {
						selection = SPT;
					} else if (Settings.unlockedViro[BLACK][HTN]) {
						selection = HTN;
					} else if (Settings.unlockedViro[BLACK][SMC]) {
						selection = SMC;
					} else {
						selection = 99;
					}
					break;
				}
				case BLACK: {

					break;
				}
				default:
					break;
				}
				postRender();
			}

		};

		slimeGreenButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				playSound(clickSound);

				selection = SLIME_GREEN;
				postRender();
			}

		};
		slimeBlueButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				playSound(clickSound);

				// TODO Auto-generated method stub
				selection = SLIME_BLUE;
				postRender();
			}

		};
		slimeRedButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				playSound(clickSound);

				// TODO Auto-generated method stub
				selection = SLIME_RED;
				postRender();
			}

		};
		slimeOrangeButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				playSound(clickSound);

				// TODO Auto-generated method stub
				selection = SLIME_ORANGE;
				postRender();
			}

		};
		duriGreenButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				playSound(clickSound);

				selection = DURI_GREEN;
				postRender();
			}

		};
		duriOrangeButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				playSound(clickSound);

				// TODO Auto-generated method stub
				selection = DURI_ORANGE;
				postRender();
			}

		};
		duriVioletButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				playSound(clickSound);

				selection = DURI_VIOLET;
				postRender();
			}

		};
		gebukGreenButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				playSound(clickSound);

				selection = GEBUK_GREEN;
				postRender();
			}

		};
		gebukPinkButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				playSound(clickSound);

				selection = GEBUK_PINK;
				postRender();
			}

		};
		gebukRedButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				playSound(clickSound);

				selection = GEBUK_RED;
				postRender();
			}

		};
		petelurBlueButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				playSound(clickSound);

				selection = PETELUR_BLUE;
				postRender();
			}

		};
		petelurVioletButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				playSound(clickSound);

				selection = PETELUR_VIOLET;
				postRender();
			}

		};
		petelurYellowButton.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				playSound(clickSound);

				// TODO Auto-generated method stub
				selection = PETELUR_YELLOW;
				postRender();
			}

		};
		rbj.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				playSound(clickSound);

				// TODO Auto-generated method stub
				selection = RBJ;
				postRender();
			}

		};
		spt.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				playSound(clickSound);

				// TODO Auto-generated method stub
				selection = SPT;
				postRender();
			}

		};
		htn.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				playSound(clickSound);

				selection = HTN;
				postRender();
			}

		};
		smc.clickListener = new ClickListener() {

			@Override
			public void clicked(Button arg0) {
				// TODO Auto-generated method stub
				playSound(clickSound);

				selection = SMC;
				postRender();
			}

		};

	}

	private void postRender() {
		stage.clear();
		if (currentShown == SLIME) {
			stage.addActor(forward);
			stage.addActor(close);
			if (Settings.unlockedViro[SLIME][SLIME_GREEN])
				stage.addActor(slimeGreenButton);
			else
				stage.addActor(locked[0]);
			if (Settings.unlockedViro[SLIME][SLIME_BLUE])
				stage.addActor(slimeBlueButton);
			else
				stage.addActor(locked[1]);
			if (Settings.unlockedViro[SLIME][SLIME_ORANGE])
				stage.addActor(slimeOrangeButton);
			else
				stage.addActor(locked[3]);
			if (Settings.unlockedViro[SLIME][SLIME_RED])
				stage.addActor(slimeRedButton);
			else
				stage.addActor(locked[2]);

			if (selection == SLIME_GREEN) {
				slimeGreenButton.y = defaultY + 5;
				slimeBlueButton.y = defaultY;
				slimeRedButton.y = defaultY;
				slimeOrangeButton.y = defaultY;
			} else if (selection == SLIME_BLUE) {
				slimeGreenButton.y = defaultY;
				slimeBlueButton.y = defaultY + 5;
				slimeRedButton.y = defaultY;
				slimeOrangeButton.y = defaultY;
			} else if (selection == SLIME_RED) {
				slimeGreenButton.y = defaultY;
				slimeBlueButton.y = defaultY;
				slimeRedButton.y = defaultY + 5;
				slimeOrangeButton.y = defaultY;
			} else if (selection == SLIME_ORANGE) {
				slimeGreenButton.y = defaultY;
				slimeBlueButton.y = defaultY;
				slimeRedButton.y = defaultY;
				slimeOrangeButton.y = defaultY + 5;
			}

		} else if (currentShown == DURI) {
			stage.addActor(back);
			stage.addActor(forward);
			stage.addActor(close);
			if (Settings.unlockedViro[DURI][DURI_GREEN])
				stage.addActor(duriGreenButton);
			else
				stage.addActor(locked[4]);
			if (Settings.unlockedViro[DURI][DURI_ORANGE])
				stage.addActor(duriOrangeButton);
			else
				stage.addActor(locked[5]);
			if (Settings.unlockedViro[DURI][DURI_VIOLET])
				stage.addActor(duriVioletButton);
			else
				stage.addActor(locked[6]);
			if (selection == DURI_GREEN) {
				duriGreenButton.y = defaultY + 5;
				duriOrangeButton.y = defaultY;
				duriVioletButton.y = defaultY;
			} else if (selection == DURI_ORANGE) {
				duriGreenButton.y = defaultY;
				duriOrangeButton.y = defaultY + 5;
				duriVioletButton.y = defaultY;
			} else if (selection == DURI_VIOLET) {
				duriGreenButton.y = defaultY;
				duriOrangeButton.y = defaultY;
				duriVioletButton.y = defaultY + 5;
			}

		} else if (currentShown == GEBUK) {
			stage.addActor(back);
			stage.addActor(forward);
			stage.addActor(close);
			if (Settings.unlockedViro[GEBUK][GEBUK_GREEN])
				stage.addActor(gebukGreenButton);
			else
				stage.addActor(locked[7]);
			if (Settings.unlockedViro[GEBUK][GEBUK_PINK])
				stage.addActor(gebukPinkButton);
			else
				stage.addActor(locked[8]);
			if (Settings.unlockedViro[GEBUK][GEBUK_RED])
				stage.addActor(gebukRedButton);
			else
				stage.addActor(locked[9]);
			if (selection == GEBUK_GREEN) {
				gebukGreenButton.y = defaultY + 5;
				gebukPinkButton.y = defaultY;
				gebukRedButton.y = defaultY;
			} else if (selection == GEBUK_PINK) {
				gebukGreenButton.y = defaultY;
				gebukPinkButton.y = defaultY + 5;
				gebukRedButton.y = defaultY;
			} else if (selection == GEBUK_RED) {
				gebukGreenButton.y = defaultY;
				gebukPinkButton.y = defaultY;
				gebukRedButton.y = defaultY + 5;
			}

		} else if (currentShown == PETELUR) {
			stage.addActor(back);
			stage.addActor(forward);
			stage.addActor(close);
			if (Settings.unlockedViro[PETELUR][PETELUR_BLUE])
				stage.addActor(petelurBlueButton);
			else
				stage.addActor(locked[10]);
			if (Settings.unlockedViro[PETELUR][PETELUR_VIOLET])
				stage.addActor(petelurVioletButton);
			else
				stage.addActor(locked[11]);
			if (Settings.unlockedViro[PETELUR][PETELUR_YELLOW])
				stage.addActor(petelurYellowButton);
			else
				stage.addActor(locked[12]);

			if (selection == PETELUR_BLUE) {
				petelurBlueButton.y = defaultY + 5;
				petelurVioletButton.y = defaultY;
				petelurYellowButton.y = defaultY;
			} else if (selection == PETELUR_VIOLET) {
				petelurBlueButton.y = defaultY;
				petelurVioletButton.y = defaultY + 5;
				petelurYellowButton.y = defaultY;
			} else if (selection == PETELUR_YELLOW) {
				petelurBlueButton.y = defaultY;
				petelurVioletButton.y = defaultY;
				petelurYellowButton.y = defaultY + 5;
			}
		} else if (currentShown == BLACK) {
			stage.addActor(back);
			stage.addActor(close);
			if (Settings.unlockedViro[BLACK][RBJ])
				stage.addActor(rbj);
			else
				stage.addActor(locked[13]);
			if (Settings.unlockedViro[BLACK][SPT])
				stage.addActor(spt);
			else
				stage.addActor(locked[14]);
			if (Settings.unlockedViro[BLACK][HTN])
				stage.addActor(htn);
			else
				stage.addActor(locked[15]);
			if (Settings.unlockedViro[BLACK][SMC])
				stage.addActor(smc);
			else
				stage.addActor(locked[16]);

			if (selection == RBJ) {
				rbj.y = defaultY + 5;
				spt.y = defaultY;
				htn.y = defaultY;
				smc.y = defaultY;

			} else if (selection == SPT) {
				rbj.y = defaultY;
				spt.y = defaultY + 5;
				htn.y = defaultY;
				smc.y = defaultY;

			} else if (selection == HTN) {
				rbj.y = defaultY;
				spt.y = defaultY;
				htn.y = defaultY + 5;
				smc.y = defaultY;

			} else if (selection == SMC) {
				rbj.y = defaultY;
				spt.y = defaultY;
				htn.y = defaultY;
				smc.y = defaultY + 5;

			}

		}
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	@Override
	public void hide() {
		// TODO Auto-generated method stub
		Resources.stopAllMusics();
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub

	}

	@Override
	public void render(float arg0) {
		// TODO Auto-generated method stub
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		camera.update();
		batch.setProjectionMatrix(camera.combined);

		batch.begin();
		batch.disableBlending();
		batch.draw(Resources.backgroundRegion, 0, 0);
		batch.draw(viroBookBg, 0, 0);
		batch.enableBlending();

		switch (currentShown) {
		case SLIME: {
			switch (selection) {
			case SLIME_GREEN: {
				batch.draw(viroSlimeGreen, 76, 122);
				batch.draw(viroTextSlime[SLIME_GREEN], x3 + 3, 122 + 64 - 80);

				break;
			}
			case SLIME_BLUE: {
				batch.draw(viroSlimeBlue, 76, 122);
				batch.draw(viroTextSlime[SLIME_BLUE], x3, 122 + 64 - 80);
				break;
			}
			case SLIME_RED: {
				batch.draw(viroSlimeRed, 76, 122);
				batch.draw(viroTextSlime[SLIME_RED], x3, 122 + 64 - 80);

				break;
			}
			case SLIME_ORANGE: {
				batch.draw(viroSlimeOrange, 76, 122);
				batch.draw(viroTextSlime[SLIME_ORANGE], x3, 122 + 64 - 80);
				break;
			}
			default:

				break;
			}
			break;
		}
		case DURI: {

			switch (selection) {
			case DURI_GREEN: {
				batch.draw(viroDuriGreen, 76, 122);
				batch.draw(viroTextDuri[DURI_GREEN], x3, 122 + 64 - 80);

				break;
			}
			case DURI_ORANGE: {
				batch.draw(viroDuriOrange, 76, 122);
				batch.draw(viroTextDuri[DURI_ORANGE], x3, 122 + 64 - 80);
				break;
			}
			case DURI_VIOLET: {
				batch.draw(viroDuriViolet, 76, 122);
				batch.draw(viroTextDuri[DURI_VIOLET], x3, 122 + 64 - 80);
				break;
			}
			default: {

				break;
			}
			}
			break;
		}
		case GEBUK: {

			switch (selection) {
			case GEBUK_GREEN: {
				batch.draw(viroGebukGreen, 76, 122);
				batch.draw(viroTextGebuk[GEBUK_GREEN], x3, 122 + 64 - 80);
				break;
			}
			case GEBUK_PINK: {
				batch.draw(viroGebukPink, 76, 122);
				batch.draw(viroTextGebuk[GEBUK_PINK], x3, 122 + 64 - 80);
				break;
			}
			case GEBUK_RED: {
				batch.draw(viroGebukRed, 76, 122);
				batch.draw(viroTextGebuk[GEBUK_RED], x3 - 3, 122 + 64 - 80);
				break;
			}
			default: {

				break;
			}
			}
			break;
		}
		case PETELUR: {

			switch (selection) {
			case PETELUR_BLUE: {
				batch.draw(viroPetelurBlue, 76, 122);
				batch.draw(viroTextPetelur[PETELUR_BLUE], x3, 122 + 64 - 80);
				break;
			}
			case PETELUR_VIOLET: {
				batch.draw(viroPetelurViolet, 76, 122);
				batch.draw(viroTextPetelur[PETELUR_VIOLET], x3 - 2,
						122 + 64 - 80);

				break;
			}
			case PETELUR_YELLOW: {
				batch.draw(viroPetelurYellow, 76, 122);
				batch.draw(viroTextPetelur[PETELUR_YELLOW], x3, 122 + 64 - 80);
				break;
			}
			default: {

				break;
			}

			}
			break;
		}
		case BLACK: {

			switch (selection) {
			case RBJ: {
				batch.draw(viroBlackRBJ, 76, 122);
				batch.draw(viroTextBlack[RBJ], x3, 122 + 64 - 80);
				break;
			}
			case SPT: {
				batch.draw(viroBlackSPT, 76, 122);
				batch.draw(viroTextBlack[SPT], x3 - 2, 122 + 64 - 80);

				break;
			}
			case HTN: {
				batch.draw(viroBlackHTN, 76, 122);
				batch.draw(viroTextBlack[HTN], x3, 122 + 64 - 80);
				break;
			}
			case SMC: {
				batch.draw(viroBlackSMC, 76, 122);
				batch.draw(viroTextBlack[SMC], x3, 122 + 64 - 80);
				break;
			}
			default: {

				break;
			}
			}
			break;
		}

		default:
			break;
		}

		batch.end();
		stage.draw();
	}

	@Override
	public void resize(int arg0, int arg1) {
		// TODO Auto-generated method stub

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void show() {
		// TODO Auto-generated method stub
		Resources.pauseAllMusics();
		Resources.playMusic(Resources.bgmViroBook);
		Gdx.input.setInputProcessor(this);
		camera.position.set(VP_WIDTH / 2, VP_HEIGHT / 2, 0);
		currentShown = SLIME;
		switch (currentShown) {
		case SLIME: {
			if (Settings.unlockedViro[SLIME][SLIME_GREEN]) {
				selection = SLIME_GREEN;
			} else if (Settings.unlockedViro[SLIME][SLIME_BLUE]) {
				selection = SLIME_BLUE;
			} else if (Settings.unlockedViro[SLIME][SLIME_ORANGE]) {
				selection = SLIME_ORANGE;
			} else if (Settings.unlockedViro[SLIME][SLIME_RED]) {
				selection = SLIME_RED;
			} else {
				selection = 99;
			}
			break;
		}
		case DURI: {

			if (Settings.unlockedViro[DURI][DURI_GREEN]) {
				selection = DURI_GREEN;
			} else if (Settings.unlockedViro[DURI][DURI_ORANGE]) {
				selection = DURI_ORANGE;
			} else if (Settings.unlockedViro[DURI][DURI_VIOLET]) {
				selection = DURI_VIOLET;
			} else {
				selection = 99;
			}
			break;
		}
		case GEBUK: {

			if (Settings.unlockedViro[GEBUK][GEBUK_GREEN]) {
				selection = GEBUK_GREEN;
			} else if (Settings.unlockedViro[GEBUK][GEBUK_PINK]) {
				selection = GEBUK_PINK;
			} else if (Settings.unlockedViro[GEBUK][GEBUK_RED]) {
				selection = GEBUK_RED;
			} else {
				selection = 99;
			}
			break;
		}
		case PETELUR: {
			if (Settings.unlockedViro[PETELUR][PETELUR_BLUE]) {
				selection = PETELUR_BLUE;
			} else if (Settings.unlockedViro[PETELUR][PETELUR_VIOLET]) {
				selection = PETELUR_VIOLET;
			} else if (Settings.unlockedViro[PETELUR][PETELUR_YELLOW]) {
				selection = PETELUR_YELLOW;
			} else {
				selection = 99;
			}
			break;
		}
		case BLACK: {
			if (Settings.unlockedViro[BLACK][RBJ]) {
				selection = RBJ;
			} else if (Settings.unlockedViro[BLACK][SPT]) {
				selection = SPT;
			} else if (Settings.unlockedViro[BLACK][HTN]) {
				selection = HTN;
			} else if (Settings.unlockedViro[BLACK][SMC]) {
				selection = SMC;
			} else {
				selection = 99;
			}
			break;
		}

		default:
			break;
		}

		postRender();
		
		if (!Settings.modeInvisibleUnlocked){
			boolean invis= true;
			for (int i = 0; i<= BLACK;i++){
				if (i == SLIME){
					for (int j = 0; j< 4; j++){
						invis = invis && Settings.unlockedViro[SLIME][j];
					}
				}else{
					for (int j = 0; j< 3; j++){
						invis = invis && Settings.unlockedViro[i][j];
					}
				}
			}
			if (invis){
				Settings.unlockInvisMode();
			}
		}

	}

	@Override
	public boolean keyDown(int arg0) {
		// TODO Auto-generated method stub

		return false;
	}

	private void backToMainMenu() {
		// TODO Auto-generated method stub
		playSound(clickSound);
		mainListener.setState(MainAppListener.MAIN_MENU);
	}

	@Override
	public boolean keyTyped(char arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean keyUp(int arg0) {
		// TODO Auto-generated method stub
		if (arg0 == Input.Keys.DPAD_UP) {
			// Gdx.app.log("DPAT", "UP");

		} else if (arg0 == Input.Keys.DPAD_DOWN) {
			// Gdx.app.log("DPAT", "DOWN");

		} else if (arg0 == Input.Keys.DPAD_LEFT) {
			// Gdx.app.log("DPAT", "LEFT");

		} else if (arg0 == Input.Keys.DPAD_RIGHT) {
			// Gdx.app.log("DPAT", "RIGHT");

		} else if (arg0 == Input.Keys.BACK) {
			backToMainMenu();
		}
		return false;
	}

	@Override
	public boolean scrolled(int arg0) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchDown(int arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub
		return stage.touchDown(arg0, arg1, arg2, arg3);
	}

	@Override
	public boolean touchDragged(int arg0, int arg1, int arg2) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchMoved(int arg0, int arg1) {
		// TODO Auto-generated method stub
		return false;
	}

	@Override
	public boolean touchUp(int arg0, int arg1, int arg2, int arg3) {
		// TODO Auto-generated method stub
		return stage.touchUp(arg0, arg1, arg2, arg3);
	}

	public void playSound(Sound sound) {

		if (Settings.soundEnabled)
			sound.play(1);
	}

}
